package com.yunyike.utils;

import org.apache.commons.lang3.RandomStringUtils;

/**
 * @author zhengqiang.shi
 * 2015年11月18日 下午7:27:16
 */
public class PKUtils {
    private static int suffixLen = 5;

    /**
     * @Description：生成主键
     * @return 主键
     */
    public synchronized static String getPrimaryKey() {
        String currentTimeMillisStr = new Long(System.currentTimeMillis())
                .toString();
        String randomStr = RandomStringUtils.randomNumeric(suffixLen);
        String temp = currentTimeMillisStr + randomStr;

        return temp;
    }
    
    public synchronized static Long getLongOrderPrimaryKey() {
        String currentTimeMillisStr = new Long(System.currentTimeMillis()).toString();
        currentTimeMillisStr = currentTimeMillisStr.substring(2);
		String randomStr = RandomStringUtils.randomNumeric(suffixLen);
		String temp = currentTimeMillisStr + randomStr;
		
		return Long.parseLong(temp);
	}
    
}
